package com.huang.auth.endpoint;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huang.auth.constants.UserWrapperConstant;
import com.huang.auth.converter.AuthUserVOConverter;
import com.huang.auth.entity.po.AuthResourcePO;
import com.huang.auth.entity.po.AuthUserPO;
import com.huang.auth.entity.to.AuthUserResourceTO;
import com.huang.auth.entity.vo.AuthUserVO;
import com.huang.auth.service.AuthUserService;
import com.huang.entity.result.HStringResult;
import com.huang.entity.result.ResultBuilder;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author HuangShen
 * @Description authUser 服务调用
 * @create 2021-09-07 8:37
 */
@RestController(value = "authUserApi")
public class AuthUserEndpoint implements AuthUserApi {
    @Resource
    private AuthUserService authUserService;

    @Resource
    private AuthUserVOConverter authUserVOConverter;


    @Override
    public HStringResult<AuthUserVO> queryByAccount(String account) {
        QueryWrapper<AuthUserPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(UserWrapperConstant.ACCOUNT,account);
        AuthUserPO authUserPO = this.authUserService.getOne(queryWrapper);
        return ResultBuilder.successHSingle(authUserVOConverter.doConvert(authUserPO));
    }


    @Override
    public HStringResult<AuthUserResourceTO> queryResourceByUserId(Long userId) {
        List<AuthResourcePO> authResourcePOS = this.authUserService.queryResourceByUserId(userId);
        AuthUserResourceTO authUserResourceTO = new AuthUserResourceTO();
        authUserResourceTO.setAuthResourcePOS(authResourcePOS);
        authUserResourceTO.setUserId(userId);
        return ResultBuilder.successHSingle(authUserResourceTO);
    }


}
